package emulator.unittest.hardware.video;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import static org.mockito.Mockito.*;

import emulator.EmulatorException;
import emulator.GUI.display.VicDisplay;
import emulator.hardware.bus.VideoBus;
import emulator.hardware.memory.MemoryBlock;
import emulator.hardware.video.Vic6561;
import emulator.hardware.video.test.CountingClock;

public class Vic6561Test {

	private static final int PAL_SCREEN_TICKS = 22152;
	private Vic6561 vic;
	private CountingClock clock;
	private MemoryBlock memory;
	private VicDisplay display;

	@Before
	public void setUp() throws Exception
	{
		vic = new Vic6561();
		clock = new CountingClock();
		memory = new MemoryBlock(65536);
		vic.attach(new VideoBus(memory), clock);
		display = mock(VicDisplay.class);
	}

	@Test
	public void testRefreshDisplayTimingDefault() throws EmulatorException
	{
		vic.refreshDisplay(display);
		assertEquals(PAL_SCREEN_TICKS, clock.getCounterValue());
	}

	@Test
	public void testRefreshDisplayTimingWide() throws EmulatorException
	{
		vic.write(0, 8);
		vic.write(1, 21);
		vic.write(2, 26);
		vic.write(3, (vic.read(3) & 0x80) | 0x21);
		vic.write(5, 204);
		vic.refreshDisplay(display);
		assertEquals(PAL_SCREEN_TICKS, clock.getCounterValue());
	}
}
